function(convert_file file include_dir)
    get_filename_component(name ${file} NAME_WE)
    get_filename_component(directory ${file} DIRECTORY)
    get_filename_component(directory ${directory} NAME)
    string(TOUPPER ${name} NAME)
    string(TOUPPER ${directory} DIRECTORY)

    set(new_file ${include_dir}/${directory}/${name}.h)
    if (${file} IS_NEWER_THAN  ${new_file})
        file(READ ${file} content)

        string(REGEX REPLACE "\"" "\\\\\"" content "${content}")
        string(REGEX REPLACE "[\r\n]" "\\\\n\"\\\\\n\"" content "${content}")
        set(content "\"${content}\"")
        set(content "#ifndef ${DIRECTORY}_${NAME}\n#define ${DIRECTORY}_${NAME} ${content} \n#endif")

        file(WRITE ${new_file} "${content}")

        message(STATUS "Generated include file ${new_file} from ${file}")
    endif()
endfunction()

function(convert_directory src_dir target_dir)
    file(GLOB srcFiles ${src_dir}/*)
    foreach(srcfile ${srcFiles})
        convert_file(${srcfile} ${target_dir})
    endforeach()
endfunction()